﻿using System;
using System.Collections.Generic;
using System.Text;

namespace bank
{
   public  class Account
    {
        //字段
        protected string id;
        //属性
        public string Id
        {
            get
            {
                return id;
            }
            set
            {
                id = value;
            }
        }
        protected float money;
        public float Money
        {
            get
            {
                return money;
            }
            set
            {
                money = value;
            }
        }

       public void addMoney(float count)
        {
            this.Money += count;
        }
       virtual public  void subMoney(float count)
        {

            this.Money -= count;

        }
    }
  public class creditAccount : Account
    {
        //信用额度
        private float creditMoney;
        public float CreditMoney
        {
            get
            {
                return creditMoney;
            }
            set
            {
                creditMoney = value;
            }
        }
        public creditAccount(string id,float money,float creditMoney)
        {
            this.Id = id;
            this.Money = money;
            this.CreditMoney = creditMoney;
        }
        // 重写subMoney方法，取钱时候如果
        //账户没钱但是可用额度还有钱
        // 就还是可以取

        override public void subMoney(float count)
        {
            if (Money < count && Money + CreditMoney > count)
            {
                Console.WriteLine("账户:" + Id + "取走金额" + count);
                CreditMoney = CreditMoney + Money - count;
                Money = 0;
            }
            else
            {
                Money -= money;
                Console.WriteLine("账户:" + Id + "取走金额" + count);
            }
        }

    }
}
